/////precompiled////////
#include "precompiled.h"
////////////////////////


#include "prs_FrmGeomAlign.h"
#include "prs_FrmDefTemplate.h"
using namespace prs;

// TNodeFrmGeomAlign //////////////////////////////////////////////////////////

// TRuleFrmGeomAlign //////////////////////////////////////////////////////////

TRuleFrmGeomAlign::TWType TRuleFrmGeomAlign::WType;
TRuleFrmGeomAlign::THType TRuleFrmGeomAlign::HType;

TNodeFrmGeomAlignBegin TRuleFrmGeomAlign::Begin;
TNodeFrmGeomAlignBeginBase TRuleFrmGeomAlign::BeginBase;
TNodeFrmGeomAlignCenter TRuleFrmGeomAlign::Center;
TNodeFrmGeomAlignCenterBase TRuleFrmGeomAlign::CenterBase;
TNodeFrmGeomAlignEnd TRuleFrmGeomAlign::End;
TNodeFrmGeomAlignEndBase TRuleFrmGeomAlign::EndBase;
TNodeFrmGeomAlignJustify TRuleFrmGeomAlign::Justify;

//
TRuleFrmGeomAlign::TRuleFrmGeomAlign(
  snt::text::TContext &SntContext
) 
{
  attr = NULL;
  vEnSetParamAsIdent = true;
  
  snt::TReturn Return;
  snt::TFVoid F;
  snt::text::TIdent I(SntContext);
  snt::text::TSequence T(SntContext);
  snt::text::TEnumSet EnumSet(SntContext);

  RWAlign
  | F.New(this,&TRuleFrmGeomAlign::FEnableSetParamAsIdent)
    & T.New("wAlign") & T.New("=")
    & RWValue.New()
    & Return.New()
  ;

  RHAlign
  | F.New(this,&TRuleFrmGeomAlign::FEnableSetParamAsIdent) 
    & T.New("hAlign") & T.New("=")
    & RHValue.New()
    & Return.New()
  ;

  RWValue.Local(vEnSetParamAsIdent)
  | EnumSet.New(this,&TRuleFrmGeomAlign::FGetEnumWAlign)
    .SetDoEntry(this,&TRuleFrmGeomAlign::FSetEnumWAlign)
    & Return.New()

  | I.NewClosure(this,&TRuleFrmGeomAlign::FSetParamAsIdentWAlign).SetEnable(vEnSetParamAsIdent)
    & Return.New()
  ;

  RHValue.Local(vEnSetParamAsIdent)
  | EnumSet.New(this,&TRuleFrmGeomAlign::FGetEnumHAlign)
    .SetDoEntry(this,&TRuleFrmGeomAlign::FSetEnumHAlign)
    & Return.New()

  | I.NewClosure(this,&TRuleFrmGeomAlign::FSetParamAsIdentHAlign).SetEnable(vEnSetParamAsIdent)
    & Return.New()
  ;
}

//
void TRuleFrmGeomAlign::FGetEnumWAlign(snt::text::TEnumSet::TFuncGetEnumSetParams &Params)
{
  Params.OutEnumSet = &WType;
}

//
bool TRuleFrmGeomAlign::FSetEnumWAlign(snt::text::TEnumSet::TFuncDoEntryParams &Params)
{
  TWType::Enum EType = (TWType::Enum)WType.Get(Params.Token.GetNValue()).I;
  TNodeFrmGeomAlign *geomAlign;

  switch (EType) {
    case TWType::left:
      geomAlign = &Begin;
    break;
    
    case TWType::leftBase:
      geomAlign = &BeginBase;
    break;
    
    case TWType::center:
      geomAlign = &Center;
    break;
    
    case TWType::centerBase:
      geomAlign = &CenterBase;
    break;
    
    case TWType::right:
      geomAlign = &End;
    break;
    
    case TWType::rightBase:
      geomAlign = &EndBase;
    break;
    
    case TWType::justify:
      geomAlign = &Justify;
    break;
    
    default: Except("FSetEnumWAlign[default]");
  }

  attr->SetValueAsPointer( TNode::newCopyFrom(geomAlign) );
  return true;
}

//
void TRuleFrmGeomAlign::FGetEnumHAlign(snt::text::TEnumSet::TFuncGetEnumSetParams &Params)
{
  Params.OutEnumSet = &HType;
}

//
bool TRuleFrmGeomAlign::FSetEnumHAlign(snt::text::TEnumSet::TFuncDoEntryParams &Params)
{
  THType::Enum EType = (THType::Enum)HType.Get(Params.Token.GetNValue()).I;
  TNodeFrmGeomAlign *geomAlign;

  switch (EType) {
    case THType::top:
      geomAlign = &Begin;
    break;
    
    case THType::topBase:
      geomAlign = &BeginBase;
    break;
    
    case THType::center:
      geomAlign = &Center;
    break;
    
    case THType::centerBase:
      geomAlign = &CenterBase;
    break;
    
    case THType::bottom:
      geomAlign = &End;
    break;
    
    case THType::bottomBase:
      geomAlign = &EndBase;
    break;
    
    case THType::justify:
      geomAlign = &Justify;
    break;
        
    default: Except("FSetEnumHAlign[default]");
  }

  attr->SetValueAsPointer( TNode::newCopyFrom(geomAlign) );
  return true;
}

//
void TRuleFrmGeomAlign::FEnableSetParamAsIdent(snt::TParams &Params)
{
  EnableSetParamAsIdent(true);
}

//
bool TRuleFrmGeomAlign::FSetParamAsIdentHAlign(snt::text::TIdent::TFuncClosureDoEntryParams &Params)
{
  svl::TString Id = Params.Ident.GetValue().String();
  return TNodeDefTemplate::AddLinkAttrByParamId(attr,TFrmGeomHAlignValue(),Id,Params.OutError);
}

//
bool TRuleFrmGeomAlign::FSetParamAsIdentWAlign(snt::text::TIdent::TFuncClosureDoEntryParams &Params)
{
  svl::TString Id = Params.Ident.GetValue().String();
  return TNodeDefTemplate::AddLinkAttrByParamId(attr,TFrmGeomWAlignValue(),Id,Params.OutError);
}
